package com.zysstudy.web.controller;


import com.zysstudy.web.domain.entity.SecurityUser;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class LoginController {

    @Resource
    AuthenticationManager authenticationManager;

    @GetMapping("/session/login")
    public String sessionLogin(String username, String password) {

        return "";
    }


    @PostMapping("/security/login")
    public String securityLogin(String username,String password) {
        // 将用户名密码托管spring-security框架管理
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username,password);

        //进行登录认证
        Authentication authentication =  authenticationManager.authenticate(authenticationToken);
        if (authentication == null){
            throw new RuntimeException("登录失败");
        }
        SecurityUser  user = (SecurityUser) authentication.getPrincipal();
//        jwUtil.
        return "";
    }

}
